//
//  TransitionToViewController.m
//  AnimationDemo
//
//  Created by Jiaozl 2018 on 2018/9/13.
//  Copyright © 2018年 Jiaozl. All rights reserved.
//

#import "TransitionToViewController.h"
#import "ZLTransitionDelegate.h"
#import "GraduallyShowAnimation.h"
@interface TransitionToViewController ()
@property (nonatomic, strong) ZLTransitionDelegate *transitionDelegate;
@property (nonatomic, strong) GraduallyShowAnimation *gradualShowAnimation;
@end

@implementation TransitionToViewController

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.transitioningDelegate = self.transitionDelegate;
        self.modalPresentationStyle  = UIModalPresentationFullScreen;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.view.backgroundColor = [UIColor yellowColor];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)back:(id)sender
{
    if (self.didClickDismissBlock) {
        self.didClickDismissBlock(self);
    }
}

// MARK: - getter
- (ZLTransitionDelegate *)transitionDelegate
{
    if (!_transitionDelegate) {
        _transitionDelegate = [[ZLTransitionDelegate alloc] init];
        weakify(self);
        _transitionDelegate.animatedPresentTransition = ^id<UIViewControllerAnimatedTransitioning> _Nonnull{
            strongify(self);
            return self.gradualShowAnimation;
        };
        _transitionDelegate.animatedDismissalTransition = ^id<UIViewControllerAnimatedTransitioning> _Nonnull{
            strongify(self);
            return self.gradualShowAnimation;
        };
    }
    return _transitionDelegate;
}

- (GraduallyShowAnimation *)gradualShowAnimation
{
    if (!_gradualShowAnimation) {
        _gradualShowAnimation = [GraduallyShowAnimation animatedTransition];
    }
    return _gradualShowAnimation;
}

@end
